import Mock from 'mockjs';
const URL = window.config.mockService;//'http://mockData:8080/'
const filesAll = require.context('./modules', true, /\.js$/)
let modules = []
filesAll.keys().forEach(key => {
    if (key.replace(/(\.\/|\.js)/g, '') == 'index') {
        return
    }
    if (filesAll(key).default.length !== 0) {
        for (let i = 0; i < filesAll(key).default.length; i++) {
            const element = filesAll(key).default[i];
            modules.push(element)
        }
    } else {
        icu.log.capsule('配置错误', key.replace(/(\.\/|\.js)/g, '') + "无配置数据", 'error')
    }
})
Mock.setup({ timeout: '200-300' });
let InitMock = function () {
    if (modules.length !== 0) {
        for (let i = 0; i < modules.length; i++) {
            const element = modules[i];
            Mock.mock(RegExp(`${URL}${element.url}` + '.*'), element.type, function (option) {
                return element.callback(option)
            })
        }
    }
}
export {InitMock} ;




// 生成1-10随机的对象数组案例
// const { newsList } = Mock.mock({
//     'newsList|1-10': [
//         {
//             "id": "@increment()",
//             "title": "@ctitle(1,2)",
//             "content": "@cparagraph(1,2)",
//             "img_url": "@image('100x100','#FF83FA','#fcfcfc','png','图片信息')",
//             "add_time": "@date(yyyy-MM-dd hh:mm:ss)"
//         }
//     ]
// })